package com.lightsaber.trade.as.dao.archive;

import java.util.List;

import org.springframework.stereotype.Component;
import org.springside.modules.orm.Page;

import com.lightsaber.trade.as.entity.archive.ArchivedImage;
import com.lightsaber.trade.as.entity.category.Category;
import com.lightsaber.trade.core.dao.BaseDao;

@Component
public class ArchivedImageDao extends BaseDao<ArchivedImage, String> {

    public Page<ArchivedImage> findPage(final ArchivedImage archivedImage,
            final Page<ArchivedImage> page) {
        eq("planningExercise", archivedImage.getPlanningExercise());
        eq("name", archivedImage.getName());
        createAlias("planning", "p");
        eq("p.planningLevel", archivedImage.getPlanning().getPlanningLevel());
        return findPage(page);
    }

    public List<ArchivedImage> findAllByName(final String name) {
        eq("name", name);
        return list();
    }

    public List<ArchivedImage> getByPlanningExercise(final Category category) {

        createAlias("category", "c");
        eq("c.planYear", category.getPlanYear());
        return list();
    }
}
